<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>引用全局作用域中可用的全部变量</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="language.variables.superglobals.html">超全局变量</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="reserved.variables.server.html">$_SERVER</a></div>
 <div class="up"><a href="reserved.variables.html">预定义变量</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="reserved.variables.globals" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">$GLOBALS</h1>
  <p class="refpurpose"><span class="refname">$GLOBALS</span> &mdash; <span class="dc-title">引用全局作用域中可用的全部变量</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-reserved.variables.globals-description">
  <h3 class="title">说明</h3>
  <p class="para">
   一个包含了全部变量的全局组合<span class="type"><span class="type 数组">数组</span></span>。变量的名字就是数组的键。
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-reserved.variables.globals-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="variable.globals.basic">
    <p><strong>Example #1 <var class="varname"><var class="varname">$GLOBALS</var></var> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"local&nbsp;variable"</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'$foo&nbsp;in&nbsp;global&nbsp;scope:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">]&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'$foo&nbsp;in&nbsp;current&nbsp;scope:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Example&nbsp;content"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">test</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
$foo in global scope: Example content
$foo in current scope: local variable
</pre></div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-reserved.variables.globals-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">“Superglobal”也称为自动化的全局变量。这就表示其在脚本的所有作用域中都是可用的。不需要在函数或方法中用
<strong class="command">global $variable;</strong> 来访问它。</p></p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>变量可用性</strong><br />
   <p class="para">
    与所有其他<a href="language.variables.superglobals.html" class="link">超全局变量</a>不同，<var class="varname"><var class="varname">$GLOBALS</var></var>在PHP中总是可用的。
   </p>
  </p></blockquote>
 </div>

 
</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="language.variables.superglobals.html">超全局变量</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="reserved.variables.server.html">$_SERVER</a></div>
 <div class="up"><a href="reserved.variables.html">预定义变量</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
